#!/usr/bin/env bash
##### 配置文件区 请自行修改到你自己的内网IP
k8sServer=30.11.99.19
imgserver=30.11.99.19



##### 配置文件结束


cat >/etc/yum.repos.d/k8s.repo <<EOF
[virt7-docker-common-release]
name=virt7-docker-common-release
baseurl=http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/
gpgcheck=0
EOF
yum -y install --enablerepo=virt7-docker-common-release kubernetes etcd flannel

setenforce 0
systemctl disable iptables-services firewalld
systemctl stop iptables-services firewalld

# 设置etcd 文件
mv /etc/etcd/etcd.conf  /etc/etcd/etcd.conf.bak
cat >/etc/etcd/etcd.conf<<EOF
#[Member]
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="default"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
EOF
# 配置k8s的config配置文件
mv /etc/kubernetes/config /etc/kubernetes/config.bak
cat > /etc/kubernetes/config<<EOF
###
# kubernetes system config
#
# The following values are used to configure various aspects of all
# kubernetes services, including
#
#   kube-apiserver.service
#   kube-controller-manager.service
#   kube-scheduler.service
#   kubelet.service
#   kube-proxy.service
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"

# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"

# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://$k8sServer:8080"
EOF
# 配置APISERVER
mv /etc/kubernetes/apiserver /etc/kubernetes/apiserver.bak
cat >/etc/kubernetes/apiserver<<EOF
###
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#

# The address on the local server to listen to.
KUBE_API_ADDRESS="--insecure-bind-address=$k8sServer"

# The port on the local server to listen on.
 KUBE_API_PORT="--port=8078"

# Port minions listen on
# KUBELET_PORT="--kubelet-port=10250"

# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"

# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

# default admission control policies
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"

# Add your own!
KUBE_API_ARGS=""
EOF
# 配置controller-manager文件

# 配置kubelet 配置文件
mv /etc/kubernetes/kubelet /etc/kubernetes/kubelet.bak
cat >/etc/kubernetes/kubelet<<EOF

###
# kubernetes kubelet (minion) config

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=0.0.0.0"

# The port for the info server to serve on
# KUBELET_PORT="--port=10250"

# You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname-override=$k8sServer"

# location of the api-server
KUBELET_API_SERVER="--api-servers=http://$k8sServer:8078"

# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=$imgserver:5000/centos/jdk:latest"

# Add your own!
KUBELET_ARGS=""

EOF


for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done






